<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MonthlyAllow extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
 }
 function index(){
 	$roles=$this->session->userdata('roles');
 	 $config['base_url'] = base_url().'monthlyAllow/index'; 
	 $config['total_rows'] = $this->muser->num_rows('MonthlyAllow');
	 
	 $config['per_page'] = 10; // xác định số record ở mỗi trang  
     $config['uri_segment'] = 3; // xác định segment chứa page number  
	 $this->pagination->initialize($config); 
	 $data['result']=$this->muser->getalldata('MonthlyAllow',$config['per_page'],$this->uri->segment(3));	
	 
	 if ($error=$this->session->userdata('error')) {
	 	$data['error']=$error;
		$this->session->unset_userdata('error'); 
	 }
         if($roles==0||$roles==1)
         {
	 $this->load->view('_header');
        $this->load->view('monthlyAllow/monthlyAllow_view',$data); 
        $this->load->view('_footer');
         }
     else
         {
             $data['ban_roles']="You haven't this role";
             $this->load->view('_header',$data);
             $this->load->view('notAllowRole');
             $this->load->view('_footer');
         }
 }
function insert()
{
			$DT['MonthlyAllow_ID']=$this->input->post('MonthlyAllow_ID');	
		 	$DT['Allowance']=$this->input->post('Allowance');
			$DT['Amount']=$this->input->post('Amount');
			$DT['ExcutiveDate']=$this->input->post('ExcutiveDate');
			$this->muser->addData('MonthlyAllow',$DT);
			$data['error']='Insert successful!';
			redirect('monthlyAllow/index');
	
}	

 function delete($MonthlyAllow_ID){
 	if ($this->muser->checkData('MAS','MonthlyAllow_ID',$MonthlyAllow_ID)){
 		$er=$this->muser->delColumn('MonthlyAllow','MonthlyAllow_ID',$MonthlyAllow_ID);
		redirect('monthlyAllow/index'); 
 	}else{
 		$error['error']= $MonthlyAllow_ID.' is a foreign key!';
		$this->session->set_userdata($error);
		redirect('monthlyAllow/index');
 	}
	
}
 
 function edit1 ()
 {
 	$DT['MonthlyAllow_ID']=$this->input->post('MonthlyAllow_ID');	
	$DT['Allowance']=$this->input->post('Allowance');
	$DT['Amount']=$this->input->post('Amount');
	$DT['ExcutiveDate']=$this->input->post('ExcutiveDate');
	$this->muser->updateData('MonthlyAllow','MonthlyAllow_ID',$DT['MonthlyAllow_ID'],$DT);
	$data['error']='Edit successful!';	 	
	redirect('monthlyAllow/index');		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('MonthlyAllow','MonthlyAllow_ID',$str);
	$data['result']=$result;	
 	$this->load->view('_header');
	$this->load->view('monthlyAllow/editMonthlyAllow_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_monthlyAllow($str){
 		return $this->muser->checkData('MonthlyAllow','MonthlyAllow_ID',$str);		
 }
}